<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<c:set value="${pageContext.request.contextPath}" var="path"
	scope="page" />
<title>求知后台管理系统-登录</title>
<link href="${path}/css/zui.min.css" rel="stylesheet">
<script src="${path}/js/jquery-1.11.1.min.js"></script>
<script src="${path}/js/zui.min.js"></script>
<script type="text/javascript">
	function doSubmit() {
		var username = $("input[name='username']").val();
		var pwd = $("input[name='password']").val();
		var verify = $("input[name='verify']").val();
		if (username != "") {
			if (pwd != "") {
				if (verify != "") {
					var url = "${path}/AdminLoginController";
					$
							.post(
									url,
									{
										username : username,
										password : pwd,
										verify : verify
									},
									function(data) {
										if (data == "1") {
											/*密码错误*/
											$("#hint").html("用户名和密码不匹配");
											$("input[name='password']").val("");
											$("input[name='password']").focus();
											refreshCode(); /*刷新验证码*/
										} else if (data == "0") {
											/*验证码错误*/
											$("#hint").html("验证码错误");
											$("input[name='verify']").val(""); /*清空*/
											$("input[name='verify']").focus(); /*聚焦*/
											refreshCode(); /*刷新验证码*/
										} else {
											/*登录成功，跳到后台管理的主界面*/
											$("#hint").html("");
											window.location.href = "${path}/AdminMainController";/*登录成功要跳转的页面*/
										}
									});
				} else {
					$("#hint").html("请输入验证码");
					$("input[name='verify']").focus(); /*聚焦*/
				}
			} else {
				$("#hint").html("请输入密码");
				$("input[name='password']").focus(); /*聚焦*/
			}
		} else {
			$("#hint").html("请输入用户名");
			$("input[name='username']").focus(); /*聚焦*/
		}
	}
</script>
<script type="text/javascript">
	/*刷新验证码*/
	function refreshCode() {
		$("#code").attr("src",
				"${path}/VerifyCodeServlet?now=" + new Date().getTime());
	}
</script>
</head>

<body>
	<br />
	<br />
	<br />
	<div class="panel panel-primary"
		style="width: 300px; position: absolute; left: 550px; top: 170px;">
		<div class="panel-heading">您好，管理员，请登录！</div>
		<div class="panel-body">
			<center>
				<span id="hint"
					style="font-family: sans-serif; font-size: 10px; color: #ff0000;"></span>
			</center>
			<!--提示文本-->
			<div class="input-group" style="margin-top: 10px;">
				<span class="input-group-addon"><i class="icon-user"></i></span> <input
					type="text" class="form-control" name="username" placeholder="用户名" />
			</div>
			<br />
			<div class="input-group">
				<span class="input-group-addon"><i class="icon-key"></i></span> <input
					type="password" class="form-control" name="password"
					placeholder="密码" />
			</div>
			<br />
			<div class="input-group">
				<span class="input-group-addon"><i class="icon-unlock-alt"></i></span>
				<input type="text" class="form-control" placeholder="验证码"
					name="verify" style="width: 120px;" /> &nbsp;&nbsp;&nbsp;&nbsp; <img
					id="code" src="${path}/VerifyCodeServlet"
					width="90" height="30" onclick="refreshCode();" style="cursor:pointer;"/>
			</div>
		</div>
		<div class="panel-footer">
			<button class="btn btn-primary" style="width: 68px;"
				data-loading-text="正在登录..." onclick="doSubmit();">登 录</button>
		</div>
	</div>


</body>

</html>